package com.ruoyi.report_lqn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_lqn.domain.bo.ReportLqnBmjryjlbBsInfoBo;
import com.ruoyi.report_lqn.domain.vo.ReportLqnBmjryjlbBsInfoVo;
import com.ruoyi.report_lqn.domain.ReportLqnBmjryjlbBsInfo;
import com.ruoyi.report_lqn.mapper.ReportLqnBmjryjlbBsInfoMapper;
import com.ruoyi.report_lqn.service.IReportLqnBmjryjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 沥青薄膜加热试验检测记录（一）Service业务层处理
 *
 * @author tll
 * @date 2024-09-12
 */
@RequiredArgsConstructor
@Service
public class ReportLqnBmjryjlbBsInfoServiceImpl implements IReportLqnBmjryjlbBsInfoService {

    private final ReportLqnBmjryjlbBsInfoMapper baseMapper;

    /**
     * 查询沥青薄膜加热试验检测记录（一）
     */
    @Override
    @FIllBasicInfo
    public ReportLqnBmjryjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询沥青薄膜加热试验检测记录（一）列表
     */
    @Override
    public TableDataInfo<ReportLqnBmjryjlbBsInfoVo> queryPageList(ReportLqnBmjryjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLqnBmjryjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportLqnBmjryjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询沥青薄膜加热试验检测记录（一）列表
     */
    @Override
    public List<ReportLqnBmjryjlbBsInfoVo> queryList(ReportLqnBmjryjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportLqnBmjryjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLqnBmjryjlbBsInfo> buildQueryWrapper(ReportLqnBmjryjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLqnBmjryjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportLqnBmjryjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportLqnBmjryjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportLqnBmjryjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportLqnBmjryjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportLqnBmjryjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportLqnBmjryjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportLqnBmjryjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportLqnBmjryjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportLqnBmjryjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportLqnBmjryjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportLqnBmjryjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportLqnBmjryjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportLqnBmjryjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportLqnBmjryjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportLqnBmjryjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportLqnBmjryjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportLqnBmjryjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportLqnBmjryjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportLqnBmjryjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportLqnBmjryjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportLqnBmjryjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportLqnBmjryjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportLqnBmjryjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportLqnBmjryjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportLqnBmjryjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportLqnBmjryjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportLqnBmjryjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getLiqcd()), ReportLqnBmjryjlbBsInfo::getLiqcd, bo.getLiqcd());
        lqw.eq(StringUtils.isNotBlank(bo.getLiqzlbh()), ReportLqnBmjryjlbBsInfo::getLiqzlbh, bo.getLiqzlbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbhA1()), ReportLqnBmjryjlbBsInfo::getYangpbhA1, bo.getYangpbhA1());
        lqw.eq(bo.getYangZl1() != null, ReportLqnBmjryjlbBsInfo::getYangZl1, bo.getYangZl1());
        lqw.eq(bo.getQianHjzl1() != null, ReportLqnBmjryjlbBsInfo::getQianHjzl1, bo.getQianHjzl1());
        lqw.eq(bo.getShiyZl1() != null, ReportLqnBmjryjlbBsInfo::getShiyZl1, bo.getShiyZl1());
        lqw.eq(bo.getHouHjzl1() != null, ReportLqnBmjryjlbBsInfo::getHouHjzl1, bo.getHouHjzl1());
        lqw.eq(bo.getHouYpzl1() != null, ReportLqnBmjryjlbBsInfo::getHouYpzl1, bo.getHouYpzl1());
        lqw.eq(bo.getBianhZl1() != null, ReportLqnBmjryjlbBsInfo::getBianhZl1, bo.getBianhZl1());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbhA2()), ReportLqnBmjryjlbBsInfo::getYangpbhA2, bo.getYangpbhA2());
        lqw.eq(bo.getYangZl2() != null, ReportLqnBmjryjlbBsInfo::getYangZl2, bo.getYangZl2());
        lqw.eq(bo.getQianHjzl2() != null, ReportLqnBmjryjlbBsInfo::getQianHjzl2, bo.getQianHjzl2());
        lqw.eq(bo.getShiyZl2() != null, ReportLqnBmjryjlbBsInfo::getShiyZl2, bo.getShiyZl2());
        lqw.eq(bo.getHouHjzl2() != null, ReportLqnBmjryjlbBsInfo::getHouHjzl2, bo.getHouHjzl2());
        lqw.eq(bo.getHouYpzl2() != null, ReportLqnBmjryjlbBsInfo::getHouYpzl2, bo.getHouYpzl2());
        lqw.eq(bo.getBianhZl2() != null, ReportLqnBmjryjlbBsInfo::getBianhZl2, bo.getBianhZl2());
        lqw.eq(bo.getAPjz() != null, ReportLqnBmjryjlbBsInfo::getAPjz, bo.getAPjz());
        lqw.eq(bo.getYangpbhB1() != null, ReportLqnBmjryjlbBsInfo::getYangpbhB1, bo.getYangpbhB1());
        lqw.eq(bo.getQianZrd1() != null, ReportLqnBmjryjlbBsInfo::getQianZrd1, bo.getQianZrd1());
        lqw.eq(bo.getHouZrd1() != null, ReportLqnBmjryjlbBsInfo::getHouZrd1, bo.getHouZrd1());
        lqw.eq(bo.getBianhZrdb1() != null, ReportLqnBmjryjlbBsInfo::getBianhZrdb1, bo.getBianhZrdb1());
        lqw.eq(bo.getYangpbhB2() != null, ReportLqnBmjryjlbBsInfo::getYangpbhB2, bo.getYangpbhB2());
        lqw.eq(bo.getQianZrd2() != null, ReportLqnBmjryjlbBsInfo::getQianZrd2, bo.getQianZrd2());
        lqw.eq(bo.getHouZrd2() != null, ReportLqnBmjryjlbBsInfo::getHouZrd2, bo.getHouZrd2());
        lqw.eq(bo.getBianhZrdb2() != null, ReportLqnBmjryjlbBsInfo::getBianhZrdb2, bo.getBianhZrdb2());
        lqw.eq(bo.getBPjz() != null, ReportLqnBmjryjlbBsInfo::getBPjz, bo.getBPjz());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbhC1()), ReportLqnBmjryjlbBsInfo::getYangpbhC1, bo.getYangpbhC1());
        lqw.eq(bo.getQianRhd1() != null, ReportLqnBmjryjlbBsInfo::getQianRhd1, bo.getQianRhd1());
        lqw.eq(bo.getHouRhd1() != null, ReportLqnBmjryjlbBsInfo::getHouRhd1, bo.getHouRhd1());
        lqw.eq(bo.getRhdZz1() != null, ReportLqnBmjryjlbBsInfo::getRhdZz1, bo.getRhdZz1());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbhC2()), ReportLqnBmjryjlbBsInfo::getYangpbhC2, bo.getYangpbhC2());
        lqw.eq(bo.getQianRhd2() != null, ReportLqnBmjryjlbBsInfo::getQianRhd2, bo.getQianRhd2());
        lqw.eq(bo.getHouRhd2() != null, ReportLqnBmjryjlbBsInfo::getHouRhd2, bo.getHouRhd2());
        lqw.eq(bo.getRhdZz2() != null, ReportLqnBmjryjlbBsInfo::getRhdZz2, bo.getRhdZz2());
        lqw.eq(bo.getC1Pjz() != null, ReportLqnBmjryjlbBsInfo::getC1Pjz, bo.getC1Pjz());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbhC3()), ReportLqnBmjryjlbBsInfo::getYangpbhC3, bo.getYangpbhC3());
        lqw.eq(bo.getQianRhd3() != null, ReportLqnBmjryjlbBsInfo::getQianRhd3, bo.getQianRhd3());
        lqw.eq(bo.getHouRhd3() != null, ReportLqnBmjryjlbBsInfo::getHouRhd3, bo.getHouRhd3());
        lqw.eq(bo.getRhdZz3() != null, ReportLqnBmjryjlbBsInfo::getRhdZz3, bo.getRhdZz3());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbhC4()), ReportLqnBmjryjlbBsInfo::getYangpbhC4, bo.getYangpbhC4());
        lqw.eq(bo.getQianRhd4() != null, ReportLqnBmjryjlbBsInfo::getQianRhd4, bo.getQianRhd4());
        lqw.eq(bo.getHouRhd4() != null, ReportLqnBmjryjlbBsInfo::getHouRhd4, bo.getHouRhd4());
        lqw.eq(bo.getRhdZz4() != null, ReportLqnBmjryjlbBsInfo::getRhdZz4, bo.getRhdZz4());
        lqw.eq(bo.getC3Pjz() != null, ReportLqnBmjryjlbBsInfo::getC3Pjz, bo.getC3Pjz());
        return lqw;
    }

    /**
     * 新增沥青薄膜加热试验检测记录（一）
     */
    @Override
    public Boolean insertByBo(ReportLqnBmjryjlbBsInfoBo bo) {
        ReportLqnBmjryjlbBsInfo add = BeanUtil.toBean(bo, ReportLqnBmjryjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改沥青薄膜加热试验检测记录（一）
     */
    @Override
    public Boolean updateByBo(ReportLqnBmjryjlbBsInfoBo bo) {
        ReportLqnBmjryjlbBsInfo update = BeanUtil.toBean(bo, ReportLqnBmjryjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLqnBmjryjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除沥青薄膜加热试验检测记录（一）
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
